%{
  #include "object.h"
  #include "y.tab.h"
  #include <string.h>

  int s_exp;
  int linha;
  int numero;
%}

DIGITO                   [0-9]
LETRA                    [A-Za-z]

%x STR COMMENT

%%

\"                	{yytext[yyleng-1]; yymore();BEGIN STR;}
<STR>\"           	{BEGIN INITIAL;yytext[yyleng-1];yymore(); yylval.s = (char *) strdup(yytext); return STRING;}
<STR>.            	{yytext[yyleng-1]; yymore();}

"//".*				;
"/*"				BEGIN COMMENT;
<COMMENT>"*/"       BEGIN INITIAL;
<COMMENT>"\n"       ;
<COMMENT>.   		;


"'"                 {numero++; return '\'';}
"("                 {numero++; s_exp++; return '(';}
")"                 {numero++; s_exp--; return ')';}
"."                 {numero++; return '.';}
"\n"                {linha++; numero =0;}
<<EOF>>             return EOF_F;
" "	                {numero++;}
"\t"				{numero+=8;}
[nN][iI][lL]        {numero+=3; return NIL;}
[tT]				{numero++; return T;}

{DIGITO}+			{yylval.i = atoi(yytext); numero+=strlen(yytext); return INTEIRO;}
{DIGITO}*"."({DIGITO}+|({DIGITO}+[Ee][+-]?{DIGITO}+))  {yylval.d = atof(yytext); numero+=strlen(yytext); return REAL;}
{DIGITO}"."({DIGITO}+|({DIGITO}+[Ee][+-]?{DIGITO}+))*  {yylval.d = atof(yytext); numero+=strlen(yytext); return REAL;}
{DIGITO}+[Ee][+-]?{DIGITO}*						       {yylval.d = atof(yytext); numero+=strlen(yytext); return REAL;}

[A-Za-z]*[A-Za-z0-9_\-<>=+*/%;,{}.]*	{yylval.s = (char *)strdup(yytext); numero+=strlen(yytext); return TOKEN;}

%%

int yywrap(void)
{
 return 1;
}

void * getState(void)
{
	YY_BUFFER_STATE * temp_buf = (YY_BUFFER_STATE *) malloc (sizeof(struct yy_buffer_state));
	if(yy_current_buffer)
		bcopy(yy_current_buffer,temp_buf,sizeof(struct yy_buffer_state));
	else{
		free(temp_buf);
		temp_buf = NULL;
	}
	return temp_buf;
}

void setState(void * temp_buf)
{
	if(temp_buf)
	{
		bcopy(temp_buf,yy_current_buffer,sizeof(struct yy_buffer_state));
		free(temp_buf);
	}
	else
		return;
}	
